package davey.wu.hamcrest.extend;

import static org.unitils.jmock.JmockUnitils.checking;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.unitils.UnitilsJUnit4TestClassRunner;
import org.unitils.inject.annotation.InjectIntoByType;
import org.unitils.inject.annotation.TestedObject;
import org.unitils.jmock.annotation.Jmock;

import davey.wu.mock.demo.Publisher;
import davey.wu.mock.demo.Subscriber;

@RunWith(UnitilsJUnit4TestClassRunner.class)
public class ExJmockTest2 {
	@Jmock
	@InjectIntoByType
	private Subscriber subscriber;

	@TestedObject
	private Publisher publisher = new Publisher();

	@Test
	public void test01() {
		final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(
						want(String.class).or(want(String.class).containsString("me").matcher(),
								want(String.class).containsString("get").matcher()).match(this));
			}
		});
		publisher.publish(message);
	}

	@Test
	public void test02() {
		final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(want(String.class).not().containsString("met").match(this));
			}
		});
		publisher.publish(message);
	}

	@Test
	public void test03() {
		final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(
						want(String.class).and(want(String.class).containsString("me").matcher(),
								want(String.class).containsString("ge").matcher()).match(this));
			}
		});
		publisher.publish(message);
	}

	@Test
	public void test04() {
		final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(want(String.class).not().eq("message1").match(this));
			}
		});
		publisher.publish(message);
	}

	@Test
	public void test05() {
		// final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(want(String.class).not().eq(null).match(this));
			}
		});
		publisher.publish("");
	}

	@Test
	public void test06() {
		// final String message = "message";
		checking(new ExtExpectations() {
			{
				exactly(1).of(subscriber).receive(
						want(String.class).or(want(String.class).containsString("").matcher()).match(this));
			}
		});
		publisher.publish("");
	}
}
